package com.vint.leetcode;


/*
 * 1.done easy
 * 2.string
 * ALP组成的字符串，不能超过两个A或连续三个或以上L,其它情况为true
 */
public class Leetcode551 {

    public boolean checkRecord(String s) {
        char[] str = s.toCharArray();
        int late = 0;
        int absente = 0;
        char pre = ' ';
        int max = 0;
        for(char c: str){
            if(c=='A'){
                absente++;
            }
            if(c=='L'){
                if(c==pre){
                    late++;
                    if(late>max){
                        max = late;
                    }
                } else{
                    late=1;
                }
            }
            pre = c;
        }
        if(absente>1) return false;
        if(max>=3)return false;
        return true;
    }

    //这个最简洁.*+
    public boolean checkRecord2(String s){
        return !s.matches(".*LLL.*|.*A.*A.*");
    }

    //这个也很不错
    public boolean checkRecord3(String s){
        if(s.indexOf("A") != s.lastIndexOf("A") || s.contains("LLL"))
            return false;
        return true;
    }

    public static void main(String[] args) {
        Leetcode551 leetcode551 = new Leetcode551();
        System.out.println(leetcode551.checkRecord("PPALLP"));
        System.out.println(leetcode551.checkRecord("PPALLL"));
    }
  }
